package com.enqualcomm.kids.activities;import android.Manifest;import android.animation.Animator;import android.animation.ObjectAnimator;import android.content.ContentResolver;import android.content.ContentValues;import android.content.Intent;import android.content.pm.PackageManager;import android.graphics.drawable.AnimationDrawable;import android.net.Uri;import android.os.Build;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.os.SystemClock;import android.support.annotation.NonNull;import android.support.v4.app.ActivityCompat;import android.support.v4.content.ContextCompat;import android.support.v4.util.SimpleArrayMap;import android.support.v4.view.ViewPager;import android.text.TextUtils;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.View;import android.widget.ImageView;import android.widget.RatingBar;import android.widget.TextView;import com.amap.api.maps.model.LatLng;import com.android.volley.VolleyError;import com.enqualcomm.kids.BuildConfig;import com.enqualcomm.kids.R;import com.enqualcomm.kids.base.BaseActivity;import com.enqualcomm.kids.base.MyHandler;import com.enqualcomm.kids.base.MyResultReceiver;import com.enqualcomm.kids.bean.HFNowWeather;import com.enqualcomm.kids.bean.Phone;import com.enqualcomm.kids.bean.RecentWeather;import com.enqualcomm.kids.bean.StringMessage;import com.enqualcomm.kids.bean.TerminalIcon;import com.enqualcomm.kids.component.DBUtils;import com.enqualcomm.kids.component.HeartService;import com.enqualcomm.kids.component.InitContextIntentService;import com.enqualcomm.kids.component.MyContentProvider;import com.enqualcomm.kids.config.TerminalConfig;import com.enqualcomm.kids.config.userdefault.AppDefault;import com.enqualcomm.kids.config.userdefault.CacheEntry;import com.enqualcomm.kids.config.userdefault.TerminalDefault;import com.enqualcomm.kids.config.userdefault.UserDefault;import com.enqualcomm.kids.config.userdefault.UserTerminalDefault;import com.enqualcomm.kids.manager.Controller;import com.enqualcomm.kids.manager.LocationModeHandler;import com.enqualcomm.kids.manager.ModeHandler;import com.enqualcomm.kids.mvp.NetworkModel;import com.enqualcomm.kids.mvp.Presenter;import com.enqualcomm.kids.mvp.authphone.AuthPhoneDelegate;import com.enqualcomm.kids.mvp.authphone.AuthPhoneDelegateImpl;import com.enqualcomm.kids.mvp.delterminal.DeleteTerminalDelegate;import com.enqualcomm.kids.mvp.delterminal.DeleteTerminalDelegateImpl;import com.enqualcomm.kids.mvp.map.IMapView;import com.enqualcomm.kids.mvp.map.InfoWindow;import com.enqualcomm.kids.mvp.map.MapPresenter;import com.enqualcomm.kids.mvp.pedometer.IPedometerView;import com.enqualcomm.kids.mvp.pedometer.PedometerPresenter;import com.enqualcomm.kids.mvp.question.QusetionModel;import com.enqualcomm.kids.mvp.reai.HeaderAdapter;import com.enqualcomm.kids.mvp.reai.LocationFencingModel;import com.enqualcomm.kids.mvp.reai.ShadowTransformer;import com.enqualcomm.kids.mvp.silent.DefaultSilentDelegate;import com.enqualcomm.kids.mvp.silent.SilentDelegate;import com.enqualcomm.kids.mvp.weather.IWeatherView;import com.enqualcomm.kids.mvp.weather.WeatherPresenter;import com.enqualcomm.kids.network.NetworkListener;import com.enqualcomm.kids.network.SetMonitorRunnable;import com.enqualcomm.kids.network.SocketRequest;import com.enqualcomm.kids.network.socket.request.SetMonitorParams;import com.enqualcomm.kids.network.socket.request.TerminalConfigParams;import com.enqualcomm.kids.network.socket.request.UpdateUserTerminalInfoParams;import com.enqualcomm.kids.network.socket.response.BasicResult;import com.enqualcomm.kids.network.socket.response.LocationResult;import com.enqualcomm.kids.network.socket.response.LocusResult;import com.enqualcomm.kids.network.socket.response.QueryUserTerminalInfoResult;import com.enqualcomm.kids.network.socket.response.SetMonitorResult;import com.enqualcomm.kids.network.socket.response.TerminalAskDataResult;import com.enqualcomm.kids.network.socket.response.TerminalConfigResult;import com.enqualcomm.kids.network.socket.response.TerminallistResult;import com.enqualcomm.kids.network.socket.response.UserReadResult;import com.enqualcomm.kids.view.HeaderViewPager;import com.enqualcomm.kids.view.ImageUtils;import com.enqualcomm.kids.view.ReaiBookView;import com.enqualcomm.kids.view.dialog.CommitDialogCallBack;import com.enqualcomm.kids.view.dialog.DialPhoneDialog;import com.enqualcomm.kids.view.dialog.DialPhoneNumberCallBack;import com.enqualcomm.kids.view.dialog.MonitorDialog;import com.enqualcomm.kids.view.dialog.MyPromptDialog;import com.facebook.drawee.view.SimpleDraweeView;import com.igexin.sdk.PushManager;import com.tbruyelle.rxpermissions.RxPermissions;import org.androidannotations.annotations.AfterViews;import org.androidannotations.annotations.Click;import org.androidannotations.annotations.EActivity;import org.androidannotations.annotations.UiThread;import org.androidannotations.annotations.ViewById;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.concurrent.TimeUnit;import common.utils.DensityUtil;import common.utils.MyFrontUtil;import common.utils.MyLogger;import common.utils.NetUtil;import common.utils.PermissionUtils;import common.utils.PromptUtil;import de.greenrobot.event.EventBus;import rx.Observable;import rx.Subscription;import rx.android.schedulers.AndroidSchedulers;import rx.functions.Action1;import rx.functions.Func1;import rx.schedulers.Schedulers;import static com.enqualcomm.kids.R.id.constellation_iv;@EActivity(R.layout.activity_reai_main)public class MainActivity extends BaseActivity implements IPedometerView, IWeatherView, IMapView {    private static final int ADD_TERMINAL = 0;    private static final int DELETE_TERMINAL = 1;    private static final int CHAT = 2;    private static final int STORAGE = 3;    private static final int READ_CONTACTS = 4;    private static final int TERMINAL_INFO = 5;    private static final int LOCATION = 6;    AppDefault appDefault;    UserDefault userDefault;    Controller mConroller;    List<TerminallistResult.Terminal> mTerminals;    TerminallistResult.Terminal selectedTerminal;    UserTerminalDefault mCurrentUserTerminalDefault;    MapPresenter mCurrentMapPresenter;    TerminalDefault mCurrentTermianal;    TerminalDefault[] mTerminalDefaults;    UserTerminalDefault[] mUserTerminalDefaults;    @ViewById(R.id.viewPager)    HeaderViewPager viewPager;    @ViewById(R.id.pedometer_tv)    TextView pedometer_tv;    @ViewById(R.id.weather_iv)    SimpleDraweeView weather_iv;    @ViewById(R.id.weather_tv)    TextView weather_tv;    //    @ViewById(R.id.constellation_iv)//    ReaiBookView constellation_iv;    @ViewById(R.id.chat_red_point)    TextView chat_red_point;    //    @ViewById(R.id.terminal_name_tv)//    TextView terminal_name_tv;//    @ViewById(R.id.header_iv)//    SimpleDraweeView header_iv;    @ViewById(R.id.location_fenging_tv)    TextView location_fenging_tv;    @ViewById(R.id.location_mode_tv)    TextView location_mode_tv;    @ViewById(R.id.location_time_tv)    TextView location_time_tv;    @ViewById(R.id.location_battery_tv)    TextView location_battery_tv;    @ViewById(R.id.location_battery_iv)    ImageView location_battery_iv;    //    @ViewById(R.id.terminal_list)//    TerminalListView terminal_list;    //    @ViewById(R.id.chimney_iv)//    ImageView chimney_iv;//    @ViewById(R.id.red_flag_iv)//    ImageView red_flag_iv;    @ViewById(R.id.flip_iv)    ImageView flip_iv;    @ViewById(R.id.zainaer_rl)    ReaiBookView zainaer_rl;    @ViewById(R.id.aizhishi_rl)    ReaiBookView aizhishi_rl;    @ViewById(R.id.kanshijie_rl)    ReaiBookView kanshijie_rl;    @ViewById(R.id.oscard_rl)    ReaiBookView oscard_rl;    @ViewById(R.id.zainaer_rl_bg)    ImageView zainaer_rl_bg;    @ViewById(R.id.ratingBar)    RatingBar ratingBar;    @ViewById(R.id.reward_content_tv)    TextView reward_content_tv;    @ViewById(R.id.book_marker1)    ImageView book_marker1;    @ViewById(R.id.book_marker2)    ImageView book_marker2;    @ViewById(R.id.book_marker3)    ImageView book_marker3;    @ViewById(R.id.book_marker4)    ImageView book_marker4;    //    @ViewById(R.id.time_btn_rl)//    RelativeLayout time_btn_rl;    @ViewById(R.id.current_address_tv)    TextView current_address_tv;    @ViewById(R.id.reai_bear_iv)    ImageView reai_bear_iv;    @ViewById(R.id.aizhishi_bear_iv)    ImageView aizhishi_bear_iv;    @ViewById(R.id.kanshijie_bear_iv)    ImageView kanshijie_bear_iv;    @ViewById(R.id.card_view)    View card_view;    @ViewById(R.id.card_view_shadow)    ImageView card_view_shadow;    /**     * key:头像地址，value:名字     *///    List<TerminalIcon> imageList;//    TerminalHeaderAdapter adapter;    MapPresenter[] mMapPresenters;    WeatherPresenter[] mWeatherPresenters;    SimpleArrayMap<String, AuthPhoneDelegate> authPhoneDelegates;    PedometerPresenter pedometerPresenter;    DeleteTerminalDelegate viewDelagate;    SilentDelegate silentDelegate;    LocationFencingModel locationFencingModel;    Subscription locationFencingsubscription;    Subscription locationAddressSubscription;    private static final int MODE_ZAINAER = 0;    private static final int MODE_AIZHISHI = 1;    private static final int MODE_OSCARD = 2;    private static final int MODE_KANSHIJIE = 3;    int mCurrentMode;    int book_marker_offset1;    int book_marker_offset2;    private QusetionModel qusetionModel;    private ShadowTransformer shadowTransformer;    @AfterViews    void setupViews() {        File file = new File(getApplicationContext().getFilesDir(), "PushFlag");        if (!file.exists()) {            try {                file.createNewFile();            } catch (IOException e) {                e.printStackTrace();            }        }        viewPager.setOffscreenPageLimit(3);        book_marker_offset1 = DensityUtil.dip2px(this, 12);        book_marker_offset2 = DensityUtil.dip2px(this, 10);        mCurrentMode = MODE_ZAINAER;        book_marker1.setSelected(true);        book_marker1.setTranslationY(-book_marker_offset1);//上移到书面上        checkPermission();        PushManager.getInstance().initialize(getApplicationContext());        Intent intent = new Intent(this, HeartService.class);        intent.setAction(HeartService.START);        startService(intent);        mConroller = Controller.getInstance();        qusetionModel = new QusetionModel();        pedometerPresenter = new PedometerPresenter(this);//计步        pedometerPresenter.attachView(this);        viewDelagate = new DeleteTerminalDelegateImpl(this);//删除手表//        silentDelegate = new SilentDelegateImpl(this);//上课静默//        silentDelegate.setSilentToken(silence_iv);        silentDelegate = new DefaultSilentDelegate();//空实现        locationFencingModel = new LocationFencingModel();//判断是否在电子围栏里面        locationAddressSubscription = locationFencingModel.addressChange().onBackpressureDrop().subscribe(new Action1<LocationResult.Data>() {            @Override            public void call(LocationResult.Data data) {                if (selectedTerminal != null && selectedTerminal.terminalid.equals(data.terminalid)) {                    String time = new StringBuilder(data.datetime.substring(8, 12)).insert(2, getString(R.string.main_hour)).insert(5, getString(R.string.minute)).toString();                    location_time_tv.setText(time);                    if (mTerminals != null && mTerminals.size() != 0) {                        InfoWindow.setBattery(location_battery_iv, location_battery_tv, data.battery, data.batteryBar);                        location_battery_iv.setVisibility(View.VISIBLE);                    }                    current_address_tv.setText("");                    if (!TextUtils.isEmpty(data.address) && (mTerminals != null && mTerminals.size() != 0)) {                        location_fenging_tv.setText("");                        if (data.address.equals("{}") || data.address.equals("{ }")) {                            data.address = "";                        }                        current_address_tv.setText(data.address);                    }                    /**处理天气更新和天气界面显示*/                    if (data.googleLng != 0 && data.googleLat != 0) {                        TerminalDefault terminalDefault = new TerminalDefault(selectedTerminal.terminalid);                        terminalDefault.setCityName("");                        terminalDefault.setLat(data.googleLat + "");                        terminalDefault.setLng(data.googleLng + "");                        showLocation(data);                    }                } else {                    location_time_tv.setText("");                }            }        });        ratingBar.setNumStars(5);        ratingBar.setOnTouchListener(new View.OnTouchListener() {//不允许滑动进度条            @Override            public boolean onTouch(View view, MotionEvent motionEvent) {                return true;            }        });//        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/123.ttf");//        pedometer_tv.setTypeface(typeface);        bindData();        EventBus eventBus = EventBus.getDefault();        if (!eventBus.isRegistered(this)) {            eventBus.register(this);        }        zainaer_rl.setOnFlipListener(flipListener);        aizhishi_rl.setOnFlipListener(flipListener);        kanshijie_rl.setOnFlipListener(flipListener);        oscard_rl.setOnFlipListener(flipListener);//        constellation_iv.setOnFlipListener(flipListener);    }    private ReaiBookView.FlipListener flipListener = new ReaiBookView.FlipListener() {        @Override        public void onFlipLeft() {            // 在哪儿：0            // 艾知识：1            // 奥狮卡：2            // 看世界：3            int targetMode = mCurrentMode + 1;            if (targetMode == MODE_AIZHISHI) {//艾知识                if (mConroller.isOldMainMode() || mConroller.isPet_product_enable() || !mConroller.isQ_a_enable()) {//不支持艾知识,翻到奥狮卡                    targetMode++;                }            }            if (targetMode == MODE_OSCARD) {//奥狮卡                if (!mConroller.oscard_enable()) {//不支持奥狮卡，翻到看世界                    targetMode++;                }            }            if (targetMode == MODE_KANSHIJIE) {//看世界                if (!mConroller.isfind()) {//不支持看世界，停留在当前界面                    targetMode++;                }            }            if (targetMode <= 3) {                doFlip(targetMode);            }        }        @Override        public void onFlipRight() {            int targetMode = mCurrentMode - 1;//            if (targetMode==MODE_KANSHIJIE){//                if (!mConroller.isfind()){//不支持看世界//                    targetMode--;//                }//            }            if (targetMode == MODE_OSCARD) {//奥狮卡                if (!mConroller.oscard_enable()) {//不支持奥狮卡，翻到艾知识                    targetMode--;                }            }            if (targetMode == MODE_AIZHISHI) {//艾知识                if (mConroller.isOldMainMode() || mConroller.isPet_product_enable() || !mConroller.isQ_a_enable()) {//不支持艾知识，翻到在哪儿                    targetMode--;                }            }            if (targetMode >= 0) {                doFlip(targetMode);            }        }    };    private void doFlip(int targetMode) {        long currentTimeMillis = SystemClock.elapsedRealtime();        if (currentTimeMillis - lastFlipTimeMillis > 1000) {            changeMode(targetMode);            lastFlipTimeMillis = currentTimeMillis;        }    }    private void bindData() {        appDefault = new AppDefault();        userDefault = new UserDefault(appDefault.getUserid());        mTerminals = userDefault.getTerminals();        pedometerPresenter.startPedo(mTerminals);//        不是新热艾就隐藏掉熊        if ("度度-新热艾".equals(BuildConfig.CHANNEL)) {            reai_bear_iv.setVisibility(View.VISIBLE);            aizhishi_bear_iv.setVisibility(View.VISIBLE);            kanshijie_bear_iv.setVisibility(View.VISIBLE);        } else {            aizhishi_bear_iv.setVisibility(View.INVISIBLE);            kanshijie_bear_iv.setVisibility(View.INVISIBLE);            reai_bear_iv.setVisibility(View.INVISIBLE);        }        if (mTerminals == null || mTerminals.isEmpty()) {            //如果没有手表，直接跳转到添加手表界面            selectedTerminal = null;            initBlackboard();            addTerminal();            if (headerAdapter != null) {//并不是第一次刷新界面，需要重置之前的设置                pedometer_tv.setVisibility(View.INVISIBLE);                weather_iv.setVisibility(View.INVISIBLE);                weather_tv.setText("");//                terminal_name_tv.setText("");//                constellation_iv.setBackgroundColor(getResources().getColor(R.color.transparent));//                constellation_iv.setClickable(false);                viewPager.setAdapter(new HeaderAdapter(null));            }//            header_iv.setImageURI(ImageUriFactory.getResUri(R.drawable.reai_terminal_icon));        } else {            if (viewPager != null) {                viewPager.setCurrentItem(0);            }            init();            initTerminalHeaders();            viewDelagate.setTerminals(mTerminals);        }    }    private void init() {        int size = mTerminals.size();        release(mMapPresenters);        release(mWeatherPresenters);        mMapPresenters = new MapPresenter[size];        mWeatherPresenters = new WeatherPresenter[size];        mTerminalDefaults = new TerminalDefault[size];        mUserTerminalDefaults = new UserTerminalDefault[size];        for (int i = 0; i < size; i++) {            TerminallistResult.Terminal terminal = mTerminals.get(i);            mTerminalDefaults[i] = new TerminalDefault(terminal.terminalid);            mUserTerminalDefaults[i] = new UserTerminalDefault(terminal.userterminalid);            mWeatherPresenters[i] = new WeatherPresenter(this, terminal.terminalid);            mWeatherPresenters[i].attachView(this);            mMapPresenters[i] = new MapPresenter(terminal.terminalid, false);            mMapPresenters[i].attachView(this);            mMapPresenters[i].locationSync();            //查询未读消息数量            DBUtils.queryMsgCount(this, terminal);        }    }    HeaderAdapter headerAdapter;    private void initTerminalHeaders() {        List<TerminalIcon> imageList = getImages();        headerAdapter = new HeaderAdapter(imageList);        shadowTransformer = new ShadowTransformer(viewPager, headerAdapter, card_view, card_view_shadow);        viewPager.setAdapter(headerAdapter);        viewPager.setPageTransformer(false, shadowTransformer);        if (imageList.size() - 1 < selectedPosition) {            changeTerminal(0);            MapPresenter.syncTime(appDefault.getUserkey(), appDefault.getUserid(), mTerminals.get(0).terminalid);//            shadowTransformer.resetHeaderView(0);            viewPager.setCurrentItem(0);        } else {            changeTerminal(selectedPosition);            MapPresenter.syncTime(appDefault.getUserkey(), appDefault.getUserid(), mTerminals.get(selectedPosition).terminalid);//            shadowTransformer.resetHeaderView(selectedPosition);            viewPager.setCurrentItem(selectedPosition);        }        shadowTransformer.setListener(new ShadowTransformer.SelectedTerminalChangeListener() {            @Override            public void onChange(int position) {                changeTerminal(position);            }            @Override            public void onClick(int position) {                if (selectedTerminal != null)                    startActivityWithTerminal(TerminalInfoActivity_.class, selectedTerminal);            }            @Override            public void onLongClick(int position) {                deleteTerminal();            }        });    }    @ViewById(R.id.root)    View rootView;    @ViewById(R.id.app_setting_btn)    View app_setting_btn;    //    @ViewById(R.id.all_terminals_btn)//    View all_terminals_btn;    @ViewById(R.id.dial_btn)    View dial_btn;    @ViewById(R.id.dial_tv)    TextView dial_tv;    @ViewById(R.id.chat_btn)    View chat_btn;    @ViewById(R.id.chat_tv)    TextView chat_tv;    @ViewById(R.id.phone_book_btn)    View phone_book_btn;    @ViewById(R.id.time_tv)    TextView time_tv;    @ViewById(R.id.control_btn)    View control_btn;    @ViewById(R.id.control_tv)    TextView control_tv;    int selectedPosition;    private void changeTerminal(int position) {        if (position < 0 || position >= mTerminals.size()) {            /**清理微话红点*/            chat_red_point.setText("");            return;        }        selectedPosition = position;        mCurrentTermianal = mTerminalDefaults[position];        mCurrentUserTerminalDefault = mUserTerminalDefaults[position];        selectedTerminal = mTerminals.get(position);        mCurrentMapPresenter = mMapPresenters[position];        /**服务器参数设定*///        mConroller.reset(mCurrentTermianal.getNewConfig());        /**手表参数设置定*/        mConroller.resetTerminalConfig(mCurrentTermianal.getConfig());//        initBlackboard();        //TODO 主题切换        ModeHandler modeHandler = mConroller.getModeHandler();        int targetMode = mCurrentMode;        if (targetMode == MODE_KANSHIJIE) {            if (!mConroller.isfind()) {//不支持看世界                targetMode--;            }        }        if (targetMode == MODE_OSCARD) {            if (!mConroller.oscard_enable()) {//不支持奥狮卡                targetMode--;            }        }        if (targetMode == MODE_AIZHISHI) {            if (mConroller.isOldMainMode() || mConroller.isPet_product_enable() || !mConroller.isQ_a_enable()) {//不支持艾知识，翻到在哪儿                targetMode--;            }        }        if (targetMode != mCurrentMode) {            changeModeWithoutAnimation(targetMode);        }        modeHandler.initMode(this, rootView                , mConroller.isQ_a_enable(), mConroller.isfind(), mConroller.isfamily_enable(), mConroller.isWechat_enable(), mConroller.ismake_call_enable()                , mCurrentUserTerminalDefault, null, mConroller.oscard_enable(), shadowTransformer);        silentDelegate.changeTerminal(selectedTerminal.terminalid);        /**根据定位模式*/        initMainViewByWorkMode();        if (locationFencingsubscription != null && !locationFencingsubscription.isUnsubscribed()) {            locationFencingsubscription.unsubscribe();        }        locationFencingsubscription = locationFencingModel.locationChange(mCurrentTermianal.getTerminalid())                .onBackpressureDrop().subscribe(new Action1<String>() {                    @Override                    public void call(String s) {                        //根据模式选择对应的书本图片                        if (mTerminals == null || mTerminals.size() == 0) {                            return;                        }                        if ("手动定位".equals(s)) {                            location_mode_tv.setText("");                            location_fenging_tv.setText(getString(R.string.manual_locate));//无场景                            current_address_tv.setText("");                            if (mConroller.isOldMainMode()) {                                zainaer_rl_bg.setBackgroundResource(R.drawable.bg_reai_book1_non_old);                            } else if (mConroller.isPet_product_enable()) {                                zainaer_rl_bg.setBackgroundResource(R.drawable.bg_reai_book1_non_pet);                            } else {                                zainaer_rl_bg.setBackgroundResource(R.drawable.bg_reai_book1_non);                            }                        } else {                            if ("已关机".equals(s)) {                                location_mode_tv.setText("");                                current_address_tv.setText("");                                pedometer_tv.setVisibility(View.INVISIBLE);                                weather_tv.setVisibility(View.INVISIBLE);                                weather_iv.setVisibility(View.INVISIBLE);                                location_time_tv.setVisibility(View.INVISIBLE);                                location_battery_tv.setVisibility(View.INVISIBLE);                                location_battery_iv.setVisibility(View.INVISIBLE);                            } else {                                location_mode_tv.setText("(" + getString(R.string.smart_locate) + ")");                                pedometer_tv.setVisibility(mConroller.isSupportPedometer() ? View.VISIBLE : View.INVISIBLE);                                weather_tv.setVisibility(mConroller.isweather_enable() ? View.VISIBLE : View.INVISIBLE);                                weather_iv.setVisibility(mConroller.isweather_enable() ? View.VISIBLE : View.INVISIBLE);                                location_time_tv.setVisibility(View.VISIBLE);                                location_battery_tv.setVisibility(View.VISIBLE);                                location_battery_iv.setVisibility(View.VISIBLE);                            }                            if (s != null) {                                if (s.equals("{}") || s.equals("{ }")) {                                    s = "";                                }                                Integer modeInteger = locationModeName.get(s);                                if (modeInteger != null) {                                    location_fenging_tv.setText(getString(modeInteger));                                    current_address_tv.setText("");                                } else {                                    location_fenging_tv.setText(s);                                    current_address_tv.setText("");                                }                                current_address_tv.setText("");                            }                        }                    }                });    }    private void getStartCount(final String terminalid) {        qusetionModel.getAskData(appDefault.getUserid(), appDefault.getUserkey(), terminalid, 1, new NetworkListener<TerminalAskDataResult>() {            @Override            public void onError(VolleyError error) {            }            @Override            public void onSuccess(TerminalAskDataResult response) {                if (response.code == 0) {                    if (selectedTerminal != null && selectedTerminal.terminalid.equals(terminalid)) {                        ratingBar.setRating(response.result.currentnum);                        reward_content_tv.setText(response.result.reward);                    }                }            }        });    }    @Override    protected void onResume() {        super.onResume();        if (selectedTerminal != null) {            MapPresenter.syncTime(appDefault.getUserkey(), appDefault.getUserid(), selectedTerminal.terminalid);        }    }    //    @LongClick(R.id.header_iv)    public void deleteTerminal() {        if (selectedTerminal != null && PermissionUtils.CheckPermission(this, Manifest.permission.READ_CONTACTS, DELETE_TERMINAL)) {            viewDelagate.doDelete(selectedTerminal, mCurrentUserTerminalDefault.getInfo().name, mCurrentTermianal.getConfig().imei);        }    }    //    @Click(R.id.header_iv)    public void startTerminalInfoActivity() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (PermissionUtils.CheckPermission(this, Manifest.permission.CAMERA, TERMINAL_INFO) && selectedTerminal != null) {                startActivityWithTerminal(TerminalInfoActivity_.class, selectedTerminal);            }        }    }    @Click(R.id.app_setting_btn)    void startAppSettingActivity() {        if (selectedTerminal != null) {            startActivityWithTerminal(AppSettingActivity_.class, selectedTerminal);        } else {            startActivity(AppSettingActivity_.class);        }    }    @Click(R.id.pedometer_tv)    void startPedometerActivity() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null)                startActivityWithTerminal(RPedometerActivity_.class, selectedTerminal);        }    }    @Click(R.id.weather_iv)    void startWeatherActivity() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null)                startActivityWithTerminal(WeatherActivity_.class, selectedTerminal);        }    }    @Click(R.id.dial_btn)    void dial() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {//			String telnumber = mCurrentUserTerminalDefault.getInfo().mobile;//			dial(telnumber);            QueryUserTerminalInfoResult.Data info = mCurrentUserTerminalDefault.getInfo();            dial(info);        }    }    @Click(R.id.chat_btn)    public void startChatActivity() {        if (!PermissionUtils.CheckPermission(this, Manifest.permission.RECORD_AUDIO, CHAT)                || !PermissionUtils.CheckPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE, STORAGE)                || !PermissionUtils.CheckPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, STORAGE)) {            return;        }        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null)                startActivityWithTerminal(ChatActivity.class, selectedTerminal);        }    }    @Click(R.id.phone_book_btn)    public void startPhoneBookActivity() {        if (!PermissionUtils.CheckPermission(this, Manifest.permission.READ_CONTACTS, READ_CONTACTS)) {            return;        }        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null)                startActivityWithTerminal(FamilyActivity.class, selectedTerminal);        }    }    @Click(R.id.control_btn)    void startTerminalSettingActivity() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null) {                startActivityWithTerminal(TerminalSettingActivity_.class, selectedTerminal);            }        }    }//    @Click(R.id.all_terminals_btn)//    void showAllTerminals() {//        if (mTerminals == null || mTerminals.isEmpty()) {//            addTerminal();//        } else {//            terminal_list.show(terminal_name_tv);//        }//    }    @Click(R.id.add_watch_btn)    public void addTerminal() {        if (!PermissionUtils.CheckPermission(this, Manifest.permission.CAMERA, ADD_TERMINAL)) {            return;        }        String products = appDefault.getProducts();        switch (products) {            case "1"://                startActivity(AddWatchWithWidActivity.class);                startActivity(AddWatchWidActivity_.class);                break;            case "2"://                startActivity(AddWatchWithCidActivity.class);                startActivity(AddWatchCidActivity_.class);                break;            case "3":                startActivity(AddWatchActivity.class);                break;            default:                startActivity(AddWatchActivity.class);                break;        }    }    DialPhoneDialog dialPhoneDialog;    private void dial(QueryUserTerminalInfoResult.Data info) {        if (info == null || ((info.mobile == null || "".equals(info.mobile)) && (info.mobile2 == null || "".equals(info.mobile2)))) {            return;        }        dialPhoneDialog = new DialPhoneDialog(this, info.areacode, info.areacode2, info.mobile, info.mobile2, info.name, new DialPhoneNumberCallBack() {            @Override            public void okNumber1(String countryCode, String number1, boolean isDial) {                if (isDial) {                    dialPhone(countryCode, number1);                    if (dialPhoneDialog != null) {                        dialPhoneDialog.dismiss();                    }                } else {                    startMonitor(countryCode, number1);//                        startMonitor(countryCode, number1);                }            }            @Override            public void okNumber2(String countryCode, String number2) {                dialPhone(countryCode, number2);                if (dialPhoneDialog != null) {                    dialPhoneDialog.dismiss();                }            }            @Override            public void cancle() {                if (dialPhoneDialog != null) {                    dialPhoneDialog.dismiss();                }            }        });        dialPhoneDialog.show();//        }    }    private void dialPhone(String countryCode, String phoneNumber) {        Uri uri = null;        String tNumber = "";        if (phoneNumber.startsWith("00")) {            tNumber = countryCode + phoneNumber.substring(2, phoneNumber.length());            uri = Uri.parse("tel:+" + tNumber);        } else {//			uri = Uri.parse("tel:+" + countryCode + phoneNumber);            if (phoneNumber.length() > 5 && countryCode.length() > 0) {                uri = Uri.parse("tel:+" + countryCode + phoneNumber);            } else if (countryCode.length() > 0) {                uri = Uri.parse("tel:+" + countryCode + phoneNumber);            } else {                uri = Uri.parse("tel:" + phoneNumber);            }        }        Intent tellPhone = new Intent(Intent.ACTION_DIAL, uri);        try {            startActivity(tellPhone);        } catch (Exception e) {            e.printStackTrace();        }    }    @Override    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {        super.onRequestPermissionsResult(requestCode, permissions, grantResults);        PermissionUtils.onRequestPermissionsResult(this, requestCode, grantResults);    }    private void checkPermission() {        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {            return;        }        RxPermissions.getInstance(this)                .request(                        Manifest.permission.ACCESS_COARSE_LOCATION,                        Manifest.permission.ACCESS_FINE_LOCATION                )                .subscribe(new Action1<Boolean>() {                    @Override                    public void call(Boolean aBoolean) {                    }                });    }    private void checkPermission(String permission, int requestNumber) {        if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {            ActivityCompat.requestPermissions(this,                    new String[]{permission}, requestNumber);        }    }    private void refresh() {        //重新获取terminallist        showProgress();        Intent intent = new Intent(this, InitContextIntentService.class);        intent.putExtra(InitContextIntentService.RECEIVER, new MyResultReceiver(new Handler(), this));        startService(intent);    }    @Override    protected void onReceiveResult(int resultCode, Bundle resultData) {        hideProgress();        if (resultCode == InitContextIntentService.SUCCESS) {            bindData();        } else {            PromptUtil.toast(getApplicationContext(), R.string.app_no_connection);        }    }    public void onEventMainThread(StringMessage message) {        switch (message.msg) {            case StringMessage.REFRESH_TERMINALLIST:                refresh();                break;            case StringMessage.EXIT:                appDefault.setBbtreeUserid(null);                appDefault.setBbtreeUserPhoneNumber(null);//                appDefault.setUserid(null);//                appDefault.setUserkey(null);//                appDefault.setLoginByWX(false);                startActivity(LoginActivity.class);//                startActivity(ChooseLoginActivity_.class);//                if ("品冠达-平安星智能".equals(BuildConfig.CHANNEL)) {//                    startActivity(LoginActivity.class);//                } else {//                    startActivity(ChooseLoginActivity_.class);//                }                finish();                break;            case StringMessage.INFO_UPDATED://手表资料有改动(如果设置的默认头像，性别变化时头像也要改变。。。)                initTerminalHeaders();//                bindData();                break;            case StringMessage.ICON_UPDATED://手表头像有改动                initTerminalHeaders();                break;            case StringMessage.MSG_COUNT_CHANGE:            case StringMessage.RECEIVE_PUSH_MSG:                if (mTerminals != null) {                    for (TerminallistResult.Terminal terminal : mTerminals) {                        DBUtils.queryMsgCount(this, terminal);                    }                    setupRedPoint();//更新完消息数量，也得刷新界面                }                break;            case StringMessage.CHANGE_OWNER:                TerminallistResult.Terminal terminal = isMyWatch(message.terminalid);                if (terminal != null) {//服务器有时候会把其他手表的信息推送过来。。。                    String userid = appDefault.getUserid();                    int msgCount = DBUtils.getMsgCount(this, userid, terminal.terminalid, MyContentProvider.OWNERCHANGE_URI);                    if (msgCount > 0) {                        String name = new UserTerminalDefault(terminal.userterminalid).getInfo().name;                        showChangeOwnerDialog(name);                        terminal.isowner = 1;                        //需要获取其他关注人信息                        viewDelagate.getWatchers(terminal.terminalid);                    }                }                break;            case StringMessage.WATCHER_LIST_UPDATED:                viewDelagate.getWatchers(message.terminalid);                break;            case StringMessage.KICK_USER:                TerminallistResult.Terminal myWatch = isMyWatch(message.terminalid);                if (myWatch != null) {//服务器有时候会把其他手表的信息推送过来。。。                    ContentResolver contentResolver = getContentResolver();                    String userid = appDefault.getUserid();                    String name = new UserTerminalDefault(myWatch.userterminalid).getInfo().name;                    List<UserReadResult.KickUser> kickUserData = DBUtils.getKickUserData(contentResolver, userid, myWatch.terminalid);                    showKickUserDialog(kickUserData, name);                }                break;            case StringMessage.OWNER://在家庭成员界面进行移交管理员操作了                TerminallistResult.Terminal mWatch = isMyWatch(message.terminalid);                if (mWatch != null) {                    mWatch.isowner = 0;                }                break;            case StringMessage.FAMILY_CHANGE:                viewDelagate.getAllWatchers();                break;            case StringMessage.CLEAR_DIALOG:                //在信息界面操作完之后，要清除主界面的对话框                if (authPhoneDelegates != null) {                    AuthPhoneDelegate authPhoneDelegate2 = authPhoneDelegates.get(message.terminalid);                    if (authPhoneDelegate2 != null) {                        authPhoneDelegate2.clear();                    }                }                break;            case StringMessage.APPLY:                TerminallistResult.Terminal myWatch2 = isMyWatch(message.terminalid);                if (myWatch2 != null) {                    String terminalName = new UserTerminalDefault(myWatch2.userterminalid).getInfo().name;                    if (authPhoneDelegates == null) {                        authPhoneDelegates = new SimpleArrayMap<>();                    }                    AuthPhoneDelegate authPhoneDelegate = authPhoneDelegates.get(message.terminalid);                    if (authPhoneDelegate == null) {                        authPhoneDelegate = new AuthPhoneDelegateImpl(message.terminalid);                        authPhoneDelegate.attach(this);                        authPhoneDelegates.put(message.terminalid, authPhoneDelegate);                    }                    authPhoneDelegate.onApplyMessage(appDefault.getUserid(), terminalName);                }                break;            case StringMessage.PASS:                showApplyResultDialog(message.terminalid, true);                break;            case StringMessage.REFUSE:                showApplyResultDialog(message.terminalid, false);                break;            case StringMessage.LOCATION_FENCING:                if (mCurrentTermianal != null && mCurrentTermianal.getTerminalid().equals(message.terminalid)) {                    locationFencingModel.reStart();                }                break;            case StringMessage.LOCATION_MODE:                changeTerminal(selectedPosition);                break;            case StringMessage.STAR_COUNT_UPDATE:                getStartCount(selectedTerminal.terminalid);                break;            case StringMessage.ADD_TERMINAL:                bindData();                break;        }    }    private TerminallistResult.Terminal isMyWatch(String terminalid) {        if (mTerminals != null) {            for (TerminallistResult.Terminal mTerminal : mTerminals) {                if (terminalid.equals(mTerminal.terminalid)) {                    return mTerminal;                }            }        }        return null;    }    private void showKickUserDialog(List<UserReadResult.KickUser> kickUserData, String watchName) {        if (!kickUserData.isEmpty()) {            UserReadResult.KickUser kickUser = kickUserData.get(0);            MyPromptDialog commitDialog = new MyPromptDialog(this, kickUser.time,                    watchName + getString(R.string.kick_from_memberlist),                    new CommitDialogCallBack() {                        @Override                        public void onCommit() {                            refresh();//重新获取数据                        }                        @Override                        public void onCancel() {                        }                    });            commitDialog.setCancelable(false);            commitDialog.show();        }    }    private void showChangeOwnerDialog(String watchName) {        MyPromptDialog commitDialog = new MyPromptDialog(this, getString(R.string.main_Transfer),                getString(R.string.main_Transfer_info),                new CommitDialogCallBack() {                    @Override                    public void onCommit() {                    }                    @Override                    public void onCancel() {                    }                });        commitDialog.setCancelable(false);        commitDialog.show();    }    private void showApplyResultDialog(String imei, final boolean pass) {        String msg = pass ? getString(R.string.allow_add_watch) : getString(R.string.refused_add_watch);        MyPromptDialog commitDialog1 = new MyPromptDialog(this, getString(R.string.apply_result),                msg + imei,                new CommitDialogCallBack() {                    @Override                    public void onCommit() {                        if (pass) {//如果没有通过，对手表数量没有影响，不需要刷新                            refresh();                        }                    }                    @Override                    public void onCancel() {                    }                });        commitDialog1.setCancelable(false);        commitDialog1.show();        //将所有同类型消息置为已读        ContentValues values = new ContentValues();        values.put("isread", 1);        getContentResolver().update(MyContentProvider.AUTHPASS_URI, values,                "imei = ? and userid = ? and isread = 0",                new String[]{imei, appDefault.getUserid()});        //修改消息数量        if (mTerminals != null) {            for (TerminallistResult.Terminal terminal : mTerminals) {                DBUtils.queryMsgCount(this, terminal);            }            setupRedPoint();//更新完消息数量，也得刷新界面        }    }    private void setupRedPoint() {        int count = selectedTerminal.chatCount + selectedTerminal.msgCount;        if (count > 0) {            chat_red_point.setText(count > 99 ? "99+" : String.valueOf(count));            chat_red_point.setVisibility(View.VISIBLE);        } else {            chat_red_point.setVisibility(View.INVISIBLE);        }    }    @Override    protected void onDestroy() {        qusetionModel.onStop();//~~~~~~~~~~        EventBus.getDefault().unregister(this);        CacheEntry.clear();        release(mMapPresenters);        release(mWeatherPresenters);        pedometerPresenter.detachView();        stopService(new Intent(this, HeartService.class));        if (authPhoneDelegates != null) {            for (int i = 0, size = authPhoneDelegates.size(); i < size; i++) {                authPhoneDelegates.valueAt(i).detach();            }        }        if (locationFencingsubscription != null && !locationFencingsubscription.isUnsubscribed()) {            locationFencingsubscription.unsubscribe();        }        if (locationAddressSubscription != null && !locationAddressSubscription.isUnsubscribed()) {            locationAddressSubscription.unsubscribe();        }        super.onDestroy();    }    @Override    protected void onStart() {        super.onStart();        silentDelegate.onStart();        locationFencingModel.start();        if (!pedometerPresenter.isRunning()) {            pedometerPresenter.startPedo(mTerminals);        }    }    @Override    protected void onStop() {        stop(mMapPresenters);        stop(mWeatherPresenters);        qusetionModel.onStop();        pedometerPresenter.onStop();        viewDelagate.onStop();        silentDelegate.onStop();        locationFencingModel.stop();        if (mCurrentTermianal != null) {            String workmode = mCurrentTermianal.getConfig().workmode;            if (!TerminalConfig.isAudoLocationMode(workmode)) {//手动模式下，要刷新terminalconfig                syncConfig(mCurrentTermianal);            }        }        super.onStop();    }    private void syncConfig(final TerminalDefault terminalDefault) {        qusetionModel.loadDataFromServer(new SocketRequest<TerminalConfigResult>(new TerminalConfigParams(appDefault.getUserkey(), terminalDefault.getTerminalid()),                new NetworkListener<TerminalConfigResult>() {                    @Override                    public void onError(VolleyError error) {                    }                    @Override                    public void onSuccess(TerminalConfigResult response) {                        if (response.code == 0) {                            terminalDefault.setConfig(response.result);                            if (mConroller == null) {                                Controller.getInstance().resetTerminalConfig(response.result);                            } else {                                mConroller.resetTerminalConfig(response.result);                            }                            initMainViewByWorkMode();                        }                    }                }));    }    @UiThread    @Override    public void updateStepCount(int count, String terminalid) {        if (selectedTerminal != null && selectedTerminal.terminalid.equals(terminalid)) {            if (mConroller.isOldMainMode()) {                pedometer_tv.setText(getString(R.string.steps) + "：" + count);            } else {                TerminalConfigResult.Data config = mCurrentTermianal.getConfig();                boolean audoLocationMode = TerminalConfig.isAudoLocationMode(config.workmode);                if (audoLocationMode) {                    pedometer_tv.setVisibility(mConroller.isSupportPedometer() ? View.VISIBLE : View.INVISIBLE);                    pedometer_tv.setText(String.valueOf(count) + "步");                }            }        }    }    private long exitTime = 0;    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {        if (keyCode == KeyEvent.KEYCODE_BACK) {            long l = SystemClock.elapsedRealtime();            if ((l - exitTime) > 2000) {                PromptUtil.toast(getApplicationContext(), R.string.press_to_exit);                exitTime = l;            } else {                finish();            }            return true;        }        return super.onKeyDown(keyCode, event);    }    private void release(Presenter[] presenters) {        if (presenters != null) {            for (Presenter presenter : presenters) {                presenter.detachView();            }        }    }    private void stop(WeatherPresenter[] presenters) {        if (presenters != null) {            for (WeatherPresenter presenter : presenters) {                presenter.onStop();            }        }    }    private void stop(MapPresenter[] presenters) {        if (presenters != null) {            for (MapPresenter presenter : presenters) {                presenter.onStop();            }        }    }    @UiThread    @Override    public void setCityName(String cityName, String terminalid) {    }    @UiThread    @Override    public void setWeatherImg(String weather, String terminalid) {        if (selectedTerminal != null && selectedTerminal.terminalid.equals(terminalid)) {            MyLogger.kLog().i("更新天气" + terminalid);            try {//                int id = mWeatherMap.get(weather);//                weather_iv.setImageResource(ImageUtils.getweatherPicPath(this,weather));                MyLogger.kLog().i("更新天气=========" + terminalid + ":" + weather);                weather_iv.setClickable(true);                weather_iv.setImageURI(Uri.parse(ImageUtils.getweatherPicPath(this, weather)));            } catch (Exception e) {                e.printStackTrace();            }        }    }    @UiThread    @Override    public void setTmp(String low, String hight, String terminalid) {        if (weather_iv.getVisibility() == View.VISIBLE) {            TerminalConfigResult.Data config = mCurrentTermianal.getConfig();            boolean audoLocationMode = TerminalConfig.isAudoLocationMode(config.workmode);            if (selectedTerminal != null && selectedTerminal.terminalid.equals(terminalid) && audoLocationMode) {                String tmp = low + "~" + hight + "°C";                weather_tv.setText(tmp);                weather_tv.setVisibility(mConroller.isweather_enable() ? View.VISIBLE : View.INVISIBLE);            }        }    }    @UiThread    @Override    public void setTemp(String temp, String terminalid) {    }    @UiThread    @Override    public void setRecentWeather(RecentWeather weather) {    }    @UiThread    @Override    public void updateHFWeatherData(String weather, HFNowWeather nowWeather) {    }    @Override    public void showLocation(LocationResult.Data locationResult) {        //找到正确的weatherPresenter，开始获取天气信息        WeatherPresenter weatherPresenter = getWeatherPresenter(locationResult.terminalid);        if (locationResult.googleLat == 0 && locationResult.googleLng == 0) {            weatherPresenter.getTodayWeather(39.909736, 116.395340);        } else {            weatherPresenter.getTodayWeather(locationResult.googleLat / 1E6, locationResult.googleLng / 1E6);        }    }    public WeatherPresenter getWeatherPresenter(String terminalid) {        for (WeatherPresenter presenter : mWeatherPresenters) {            if (presenter.getTerminalid().equals(terminalid)) {                return presenter;            }        }        return null;    }    @Override    public void showLocus(List<LocusResult.Data> locusResult) {    }    @Override    public void setLocationEnable(boolean b) {    }    @Override    public void showToast(int stringId) {    }    @Override    public void updateLastLocation(String dateTime, boolean b) {    }//	@Override//	public void powerOff() {////	}    @Override    public void updatePhoneLocation(LatLng phoneLocation) {    }    HashMap<String, Integer> locationModeName = new HashMap<String, Integer>() {        {            put("在坐车", R.string.by_car);            put("在坐地铁", R.string.metro);            put("在室内", R.string.indoor);            put("在走路", R.string.walk);            put("学校", R.string.school);            put("家里", R.string.home);            put("静止", R.string.sstatic);            put("已关机", R.string.main_power_off);        }    };    @Click(R.id.zainaer_rl_bg)    void startMapActivity() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            startActivityWithTerminal(AMapActivity_.class, selectedTerminal);        }    }    @Click(R.id.aizhishi_rl_bg)    void startMapActivity1() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null)                startActivityWithTerminal(ChildQuestionActivity_.class, selectedTerminal);        }    }    @Click(R.id.kanshijie_rl_bg)    void startMapActivity3() {//        if (mTerminals == null || mTerminals.isEmpty()) {//            addTerminal();//        } else {//            startActivityWithTerminal(SeeTheWroldActivity_.class, selectedTerminal);//        }        startActivity(SeeTheWroldActivity_.class);    }    @Click(R.id.oscard_rl_bg)    void startMapActivity2() {        if (mTerminals == null || mTerminals.isEmpty()) {            addTerminal();        } else {            if (selectedTerminal != null)                startActivityWithTerminal(OscardActivity_.class, selectedTerminal);        }    }    private void updateTerminalInfo(QueryUserTerminalInfoResult.Data info) {        UpdateUserTerminalInfoParams params = new UpdateUserTerminalInfoParams(appDefault.getUserkey(),                selectedTerminal.userterminalid,                info.birthday,                info.grade,                info.mobile,                info.name,                info.relation,                info.height,                info.weight,                info.gender,                info.mobile2,                info.mobiletype,                info.areacode,                info.areacode2);        qusetionModel.loadDataFromServer(new SocketRequest<BasicResult>(params, null));    }    long lastFlipTimeMillis;    @Click(R.id.book_marker1)    void clickBookMarker1() {        if (mCurrentMode == MODE_ZAINAER) {            return;        }        viewPager.setEnabled(false);        doFlip(MODE_ZAINAER);    }    @Click(R.id.book_marker2)    void clickBookMarker2() {        if (mCurrentMode == MODE_AIZHISHI) {            return;        }        viewPager.setEnabled(false);        doFlip(MODE_AIZHISHI);    }    @Click(R.id.book_marker3)    void clickBookMarker3() {        if (mCurrentMode == MODE_OSCARD) {            return;        }        viewPager.setEnabled(false);        doFlip(MODE_OSCARD);    }    @Click(R.id.book_marker4)    void clickBookMarker4() {        if (mCurrentMode == MODE_KANSHIJIE) {            return;        }        viewPager.setEnabled(false);        doFlip(MODE_KANSHIJIE);    }    private void changeModeWithoutAnimation(int mode) {        zainaer_rl.setVisibility(View.INVISIBLE);        aizhishi_rl.setVisibility(View.INVISIBLE);        kanshijie_rl.setVisibility(View.INVISIBLE);        oscard_rl.setVisibility(View.INVISIBLE);        switch (mCurrentMode) {            case MODE_ZAINAER:                book_marker1.setSelected(false);                book_marker1.setTranslationY(0);//                zainaer_rl.setVisibility(View.INVISIBLE);                break;            case MODE_AIZHISHI:                book_marker2.setSelected(false);                book_marker2.setTranslationY(0);//                aizhishi_rl.setVisibility(View.INVISIBLE);                break;            case MODE_KANSHIJIE:                book_marker4.setSelected(false);                book_marker4.setTranslationY(0);//                kanshijie_rl.setVisibility(View.INVISIBLE);                break;            case MODE_OSCARD:                book_marker3.setSelected(false);                book_marker3.setTranslationY(0);//                oscard_rl.setVisibility(View.INVISIBLE);                break;        }        mCurrentMode = mode;        switch (mCurrentMode) {            case MODE_ZAINAER:                book_marker1.setSelected(true);                book_marker1.setTranslationY(-book_marker_offset1);                zainaer_rl.setVisibility(View.VISIBLE);                zainaer_rl.setAlpha(1);                break;            case MODE_AIZHISHI:                book_marker2.setSelected(true);                book_marker2.setTranslationY(-book_marker_offset2);                aizhishi_rl.setVisibility(View.VISIBLE);                aizhishi_rl.setAlpha(1);                break;            case MODE_KANSHIJIE:                book_marker4.setSelected(true);                book_marker4.setTranslationY(-book_marker_offset1);                kanshijie_rl.setVisibility(View.VISIBLE);                kanshijie_rl.setAlpha(1);                break;            case MODE_OSCARD:                book_marker3.setSelected(true);                book_marker3.setTranslationY(-book_marker_offset2);                oscard_rl.setVisibility(View.VISIBLE);                oscard_rl.setAlpha(1);                break;        }    }    private void changeMode(int mode) {        switch (mCurrentMode) {            case MODE_ZAINAER:                book_marker1.setSelected(false);                book_marker1.setTranslationY(0);                if (mode == MODE_AIZHISHI) {//在哪儿-->艾知识                    showAizhishi();                    startFlipAnimation(zainaer_rl, R.drawable.anim_flip_zainaer_aizhishi);                } else if (mode == MODE_KANSHIJIE) {//在哪儿-->看世界                    showKanshijie();                    if (mConroller.isOldMainMode()) {                        startFlipAnimation(zainaer_rl, R.drawable.anim_flip_zainaer_kanshijie_old);                    } else if (mConroller.isPet_product_enable()) {                        startFlipAnimation(zainaer_rl, R.drawable.anim_flip_zainaer_kanshijie_pet);                    } else {                        startFlipAnimation(zainaer_rl, R.drawable.anim_flip_zainaer_kanshijie);                    }                } else {//在哪儿-->奥狮卡                    showOscard();                    startFlipAnimation(zainaer_rl, R.drawable.anim_flip_zainaer_oscard);                }                break;            case MODE_AIZHISHI:                book_marker2.setSelected(false);                book_marker2.setTranslationY(0);                if (mode == MODE_ZAINAER) {//艾知识-->在哪儿                    showZainaer();                    startFlipAnimation(aizhishi_rl, R.drawable.anim_flip_aizhishi_zainaer);                } else if (mode == MODE_KANSHIJIE) {//艾知识-->看世界                    showKanshijie();                    if (mConroller.isOldMainMode()) {                        startFlipAnimation(aizhishi_rl, R.drawable.anim_flip_zainaer_kanshijie_old);                    } else if (mConroller.isPet_product_enable()) {                        startFlipAnimation(aizhishi_rl, R.drawable.anim_flip_zainaer_kanshijie_pet);                    } else {                        startFlipAnimation(aizhishi_rl, R.drawable.anim_flip_aizhishi_kanshijie);                    }                } else {//艾知识-->奥狮卡                    showOscard();                    startFlipAnimation(aizhishi_rl, R.drawable.anim_flip_aizhishi_oscard);                }                break;            case MODE_KANSHIJIE:                book_marker4.setSelected(false);                book_marker4.setTranslationY(0);                if (mode == MODE_ZAINAER) {//看世界-->在哪儿                    showZainaer();                    if (mConroller.isOldMainMode()) {                        startFlipAnimation(kanshijie_rl, R.drawable.anim_flip_kanshijie_zainaer_old);                    } else if (mConroller.isPet_product_enable()) {                        startFlipAnimation(kanshijie_rl, R.drawable.anim_flip_kanshijie_zainaer_pet);                    } else {                        startFlipAnimation(kanshijie_rl, R.drawable.anim_flip_kanshijie_zainaer);                    }                } else if (mode == MODE_AIZHISHI) {//看世界-->艾知识                    showAizhishi();                    startFlipAnimation(kanshijie_rl, R.drawable.anim_flip_kanshijie_aizhishi);                } else {//看世界-->奥狮卡                    showOscard();                    startFlipAnimation(kanshijie_rl, R.drawable.anim_flip_kanshijie_oscard);                }                break;            case MODE_OSCARD:                book_marker3.setSelected(false);                book_marker3.setTranslationY(0);                if (mode == MODE_ZAINAER) {//奥狮卡-->在哪儿                    showZainaer();                    startFlipAnimation(oscard_rl, R.drawable.anim_flip_oscard_zainaer);                } else if (mode == MODE_AIZHISHI) {//奥狮卡-->艾知识                    showAizhishi();                    startFlipAnimation(oscard_rl, R.drawable.anim_flip_oscard_aizhishi);                } else {//艾陪伴-->看世界                    showKanshijie();                    if (mConroller.isOldMainMode()) {                        startFlipAnimation(oscard_rl, R.drawable.anim_flip_zainaer_kanshijie_old);                    } else if (mConroller.isPet_product_enable()) {                        startFlipAnimation(oscard_rl, R.drawable.anim_flip_zainaer_kanshijie_pet);                    } else {                        startFlipAnimation(oscard_rl, R.drawable.anim_flip_oscard_kanshijie);                    }                }                break;        }        mCurrentMode = mode;    }    private static final int FILP_ANIMATION_DURATION = 800;    private static final int FADE_ANIMATION_DURATION = 300;    /**     * 开始翻页动画     *     * @param v              当前在顶层，需要隐藏的书页     * @param animDrawableId 翻页动画drawableId     */    private void startFlipAnimation(final View v, final int animDrawableId) {//        constellation_iv.setVisibility(View.INVISIBLE);        flip_iv.setVisibility(View.VISIBLE);        flip_iv.setImageResource(animDrawableId);        viewPager.setEnabled(false);        /*ObjectAnimator */        ObjectAnimator fadeOut = ObjectAnimator.ofFloat(v, "alpha", 1, 0).setDuration(FADE_ANIMATION_DURATION);        fadeOut.addListener(new Animator.AnimatorListener() {            @Override            public void onAnimationStart(Animator animator) {            }            @Override            public void onAnimationEnd(Animator animator) {                v.setVisibility(View.INVISIBLE);                ((AnimationDrawable) flip_iv.getDrawable()).start();            }            @Override            public void onAnimationCancel(Animator animator) {                viewPager.setEnabled(true);            }            @Override            public void onAnimationRepeat(Animator animator) {            }        });        fadeOut.start();        Observable.timer(FILP_ANIMATION_DURATION + FADE_ANIMATION_DURATION * 2, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())                .subscribe(new Action1<Long>() {                    @Override                    public void call(Long aLong) {//                        constellation_iv.setVisibility(View.VISIBLE);                        flip_iv.setVisibility(View.INVISIBLE);                        viewPager.setEnabled(true);                    }                });    }    private void showZainaer() {        book_marker1.setSelected(true);        book_marker1.setTranslationY(-book_marker_offset1);        Observable.timer(FILP_ANIMATION_DURATION + FADE_ANIMATION_DURATION, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())                .subscribe(new Action1<Long>() {                    @Override                    public void call(Long aLong) {                        zainaer_rl.setVisibility(View.VISIBLE);                        ObjectAnimator.ofFloat(zainaer_rl, "alpha", 0, 1).setDuration(FADE_ANIMATION_DURATION).start();                    }                });    }    private void showAizhishi() {        book_marker2.setSelected(true);        book_marker2.setTranslationY(-book_marker_offset2);        Observable.timer(FILP_ANIMATION_DURATION + FADE_ANIMATION_DURATION, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())                .subscribe(new Action1<Long>() {                    @Override                    public void call(Long aLong) {                        aizhishi_rl.setVisibility(View.VISIBLE);                        ObjectAnimator.ofFloat(aizhishi_rl, "alpha", 0, 1).setDuration(FADE_ANIMATION_DURATION).start();                    }                });    }    private void showKanshijie() {        book_marker4.setSelected(true);        book_marker4.setTranslationY(-book_marker_offset1);        Observable.timer(FILP_ANIMATION_DURATION + FADE_ANIMATION_DURATION, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())                .subscribe(new Action1<Long>() {                    @Override                    public void call(Long aLong) {                        kanshijie_rl.setVisibility(View.VISIBLE);                        ObjectAnimator.ofFloat(kanshijie_rl, "alpha", 0, 1).setDuration(FADE_ANIMATION_DURATION).start();                    }                });    }    private void showOscard() {        book_marker3.setSelected(true);        book_marker3.setTranslationY(-book_marker_offset2);        Observable.timer(FILP_ANIMATION_DURATION + FADE_ANIMATION_DURATION, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread())                .subscribe(new Action1<Long>() {                    @Override                    public void call(Long aLong) {                        oscard_rl.setVisibility(View.VISIBLE);                        ObjectAnimator.ofFloat(oscard_rl, "alpha", 0, 1).setDuration(FADE_ANIMATION_DURATION).start();                    }                });    }    private List<TerminalIcon> getImages() {        ArrayList<TerminalIcon> arrayList = new ArrayList<>();        String imagePath;        for (int i = 0; i < mUserTerminalDefaults.length; i++) {            QueryUserTerminalInfoResult.Data info = mUserTerminalDefaults[i].getInfo();            imagePath = ImageUtils.getHeader(this                    , mTerminalDefaults[i].getTerminalid()                    , mUserTerminalDefaults[i].getUserterminalid()                    , info.gender);            arrayList.add(new TerminalIcon(imagePath, info.name));        }        return arrayList;    }    public void startLockActivity() {        startActivity(GestureLockLoginActivity_.class);        finish();    }    private void initBlackboard() {        current_address_tv.setText("");        location_fenging_tv.setText("");        location_mode_tv.setText("");        location_battery_iv.setVisibility(View.INVISIBLE);        location_battery_tv.setText("");        /**清理微话红点*/        chat_red_point.setText("");        if (mTerminals == null || mTerminals.size() == 0) {            if (mConroller == null) {                mConroller = Controller.getInstance();            }            mConroller.resetTerminalConfig(null);            ModeHandler modeHandler = mConroller.getModeHandler();            modeHandler.initMode(this, rootView                    , false, true, true, true, true                    , null, null, false, shadowTransformer);        }    }    private void initMainViewByWorkMode() {        TerminalConfigResult.Data config = mCurrentTermianal.getConfig();        boolean audoLocationMode = TerminalConfig.isAudoLocationMode(config.workmode);        LocationModeHandler locationModeHandler = mConroller.getLocationModeHandler();        locationModeHandler.initLocationMode(this, mCurrentTermianal, mCurrentMapPresenter, rootView, audoLocationMode, mConroller.isSupportPedometer()                , mConroller.isweather_enable(), mConroller.isOldMainMode());        setupRedPoint();        ratingBar.setRating(0);        reward_content_tv.setText("");        if (selectedTerminal != null)            getStartCount(selectedTerminal.terminalid);        location_fenging_tv.setText("");        location_mode_tv.setText("");        location_time_tv.setText("");        location_battery_tv.setText("");        location_battery_iv.setVisibility(View.INVISIBLE);        if (!audoLocationMode) {//            location_fenging_tv.setText(getString(R.string.manual_locate));            if (mConroller.isOldMainMode()) {                zainaer_rl_bg.setBackgroundResource(R.drawable.bg_reai_book1_non_old);            } else if (mConroller.isPet_product_enable()) {                zainaer_rl_bg.setBackgroundResource(R.drawable.bg_reai_book1_non_pet);            } else {                zainaer_rl_bg.setBackgroundResource(R.drawable.bg_reai_book1_non);            }        }    }    private MonitorDialog monitorDialog;    MyHandler monitorHandler = new MyHandler(this);    void startMonitor(String countryCode, String phone) {        //监护        SetMonitorParams setMonitorParams = new SetMonitorParams(appDefault.getUserkey(), appDefault.getUserid(), selectedTerminal.terminalid, appDefault.getUsername());        if (NetUtil.checkNet(this)) {//            PromptUtil.longToast(getApplicationContext(),R.string.monitoring);            monitorDialog = new MonitorDialog(this);            monitorDialog.show();            NetUtil.execute(new SetMonitorRunnable(monitorHandler, setMonitorParams, new UserTerminalDefault(selectedTerminal.userterminalid).getInfo(), new Phone(countryCode, phone)));        } else {            PromptUtil.toast(this, R.string.app_no_connection);        }    }    /**     * j监护模式打开     */    public void monitorOk(Message msg) {        if (monitorDialog != null) {            monitorDialog.dismiss();            monitorDialog = null;        }//        QueryUserTerminalInfoResult.Data info = (QueryUserTerminalInfoResult.Data) msg.obj;//        dial(info);        Phone phone = (Phone) msg.obj;        dialPhone(phone.phoneCountryCode, phone.phoneNumber);    }    /**     * 手表端关机     */    public void monitorPowerOff() {        if (monitorDialog != null) {            monitorDialog.setErrorMsg(R.string.cannot_monitor_by_power_off);            monitorHandler.sendEmptyMessageDelayed(100, 2000);//关掉对话框        }    }    /**     * 监听出错     */    public void monitorError() {        if (monitorDialog != null) {            monitorDialog.setErrorMsg(R.string.monitor_failure);            monitorHandler.sendEmptyMessageDelayed(100, 2000);//关掉对话框        }    }    public void monitorErrorCode() {        if (monitorDialog != null) {            monitorDialog.dismiss();            monitorDialog = null;        }    }    @Override    protected void handleMessage(Message msg) {        switch (msg.what) {            case SetMonitorRunnable.OK:                monitorOk(msg);                break;            case SetMonitorRunnable.POWER_OFF:                monitorPowerOff();                break;            case SetMonitorRunnable.ERROR:                monitorError();                break;            case 100:                monitorErrorCode();                break;        }        if (dialPhoneDialog != null && dialPhoneDialog.isShowing()) {            dialPhoneDialog.dismiss();        }    }}